<?php
ini_set ( 'session.cookie_lifetime', '36000' );
ini_set ( "session.gc_maxlifetime", '36000' );
session_start ();
if (empty ( $_SESSION ['login'] )) {
	header ( 'Location:index.php' );
	exit ();
}
?>
<?php

header ( "Cache-Control: no-store,no-cache, must-revalidate" );
header ( "Content-Type: text/html; charset=utf-8" );
require_once $_SERVER ['DOCUMENT_ROOT'] . "/bib/class/php/mysql_class.php";
// $mysql_bib = new mysql_class ( 'vksm.net.mysql', 'vksm_net', 'egDYxATy', 'vksm_net' );
$mysql_bib = new mysql_class ( 'localhost', 'root', '', 'regi' );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="design/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="prototype.js"></script>
<title>Gallery</title>

<script type="text/javascript">

function refreshComments() 
{
	var id_user = document.getElementById("id_user").value;
	new Ajax.Updater(
		'allcomments',
		'comment.php',
		{
			method: 'POST',
			parameters: {M_id_user: id_user}
		}
	);
}

function posten()
{
	var id_video = document.getElementById("id_video").value;
	var url = document.getElementById("url").value;
	var id_user = document.getElementById("id_user").value;
	var onecomment = document.getElementById("onecomment").value;
	document.getElementById('onecomment').value = "";
	
	new Ajax.Updater(
		'allcomments',
		'comment.php',
		{
			method: 'POST',
			parameters: {M_id_video: id_video, M_url: url, M_id_user: id_user, M_onecomment: onecomment}
		}
	);
	
}

</script>
</head>

<body>
<?php
echo '<h1>Willkommen ' . $_SESSION ['login'] . '</h1>';
echo '<a href="abmeldung.php">Abmelden</a>' . '<br/><br/>';
// $donnees = $mysql_bib->query ( "SELECT id FROM user WHERE pseudo = '" . $_SESSION ['login'] . "'" );
$donnees2 = $mysql_bib->query ( "SELECT * FROM videos" );
$last_regi = $mysql_bib->query ( "SELECT id, lastRegistration FROM user WHERE pseudo = '" . $_SESSION ['login'] . "'" );

foreach ( $last_regi as $elt ) {
	$regi = $elt ["lastRegistration"];
	$id_user = $elt ["id"];
}
echo 'Letzte Anmeldung: ' . $regi . '<br/><br/>';

$choreo = "Choreograf";
$freestyle = "Freestyle";

?>
<table cellspacing="20">
		<tbody>



<?php
foreach ( $donnees2 as $elt ) {
	$name = $elt ["name"];
	$url = $elt ["url"];
	$dayoftraining = $elt ["dayoftraining"];
	$id_video = $elt ["id"];
	
	?>
	
	
	<tr>
				<td style="width: 50%"><?php
	echo ($dayoftraining == '' ? '&nbsp;' : '<b><u>Am Dienstag, den ' . $dayoftraining) . '</u></b><br/><br/>';
	echo ($dayoftraining == '' ? '<b>' . $name . ' - ' . $freestyle : $name . ' - ' . $choreo);
	echo "<video width='600' height='340'controls><source src='video/$url" . "' type='video/mp4'></video>";
	?>
	</td>
				<td id="allcomments"><textarea id="allcomments" name="allcomments"
						readonly="readonly"></textarea><br> <textarea id="onecomment"
						name="onecomment"></textarea> <input type="button" value="posten"
					id="posten" onclick="posten()" /> <input type="hidden"
					id="id_video" value="<?php echo $id_video?>" /> <input
					type="hidden" id="url" value="<?php echo $url?>" /> <input
					type="hidden" id="id_user" value="<?php echo $id_user?>" /></td>

			</tr>
	

	<?php
}
?>
</tbody>
	</table>

<?php

echo '<br />';
echo '<a href="abmeldung.php">Abmelden</a>';
?>
</body>
<script> setInterval("refreshComments()", 3000); </script>
</html>
